<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="面试,神策数据," />





  <link rel="alternate" href="/atom.xml" title="justZero" type="application/atom+xml" />






<meta name="keywords" content="面试,神策数据">
<meta property="og:type" content="article">
<meta property="og:title" content="神策数据电话面试">
<meta property="og:url" content="https://alonezero.github.io/posts/a3744c3a/index.html">
<meta property="og:site_name" content="justZero">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://i.ibb.co/nBP7CCh/11.jpg">
<meta property="og:updated_time" content="2020-01-27T05:06:26.429Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="神策数据电话面试">
<meta name="twitter:image" content="https://i.ibb.co/nBP7CCh/11.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://alonezero.github.io/posts/a3744c3a/"/>





  <title>神策数据电话面试 | justZero</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?2966d6cabfe87d8db183d0b7a1e088f4";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">justZero</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">爱编程，更爱生活！</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://alonezero.github.io/posts/a3744c3a/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="justZero">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">神策数据电话面试</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-03-17T17:40:49+08:00">
                2019-03-17
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/那年编程那些事儿/" itemprop="url" rel="index">
                    <span itemprop="name">那年编程那些事儿</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/posts/a3744c3a/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/posts/a3744c3a/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/posts/a3744c3a/" class="leancloud_visitors" data-flag-title="神策数据电话面试">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="https://i.ibb.co/nBP7CCh/11.jpg" alt="Stay Hungry, Stay Foolish."></p>
<a id="more"></a>
<h2 id="HashMap-底层原理"><a href="#HashMap-底层原理" class="headerlink" title="HashMap 底层原理"></a>HashMap 底层原理</h2><p><code>HashMap</code>是以键值对（key-value）的形式存储元素的。<code>HashMap</code>需要一个<strong>hash函数</strong>，它使用<code>hashCode()</code>和<code>equals()</code>方法向集合中添加元素或从集合中检索元素。</p>
<p>当调用<code>put()</code>方法的时候，<code>HashMap</code>会计算<code>key</code>的<code>hash</code>值，然后把键值对存储在集合中合适的索引上。如果<code>key</code>已经存在了，<code>value</code>会被更新成新值。</p>
<h2 id="HashMap-如何解决哈希冲突"><a href="#HashMap-如何解决哈希冲突" class="headerlink" title="HashMap 如何解决哈希冲突"></a>HashMap 如何解决哈希冲突</h2><p>使用<strong>拉链法</strong>。</p>
<p><code>HashMap</code>中哈希表的每一个元素其实是一个链表。当发生哈希冲突时，首先从该哈希索引对应的链表中查找是否已有相同<code>key</code>，若有则更新<code>value</code>即可，否则将使用链表的头插法，将冲突的新键值对插在链表的头部。</p>
<h2 id="HashMap-和-Hashtable-的区别"><a href="#HashMap-和-Hashtable-的区别" class="headerlink" title="HashMap 和 Hashtable 的区别"></a>HashMap 和 Hashtable 的区别</h2><p>两者都实现了<code>Map</code>接口，因此很多特性非常相似。但是，他们有以下不同点：</p>
<ul>
<li><code>HashMap</code>允许键和值是<code>null</code>，而<code>Hashtable</code>不允许键或者值是<code>null</code>。</li>
<li><code>HashMap</code>随着时间的推移，无法保证元素次序是不变的。</li>
<li><code>HashMap</code>提供了<code>fail-fast</code>迭代器，即多线程环境下迭代<strong>可能会发生</strong> <code>ConcurrentModificationException</code>。</li>
<li><code>Hashtable</code>是线程安全的，而<code>HashMap</code>不是。</li>
<li><code>Hashtable</code>提供了对键的枚举（Enumeration）。</li>
</ul>
<p>一般认为<code>Hashtable</code>是一个遗留的类。</p>
<h2 id="Hashtable-如何保证线程安全"><a href="#Hashtable-如何保证线程安全" class="headerlink" title="Hashtable 如何保证线程安全"></a>Hashtable 如何保证线程安全</h2><p>因为其每个可能引发线程安全的方法均被<code>synchronized</code>关键字修饰（加上了同步锁）。</p>
<h2 id="HashMap-如何变得线程安全"><a href="#HashMap-如何变得线程安全" class="headerlink" title="HashMap 如何变得线程安全"></a>HashMap 如何变得线程安全</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line">HashMap&lt;Object, Object&gt; hashMap = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">Map&lt;Object, Object&gt; map = Collections.synchronizedMap(hashMap);</span><br></pre></td></tr></table></figure>
<h2 id="HashMap-和-LinkedHashMap-的区别"><a href="#HashMap-和-LinkedHashMap-的区别" class="headerlink" title="HashMap 和 LinkedHashMap 的区别"></a>HashMap 和 LinkedHashMap 的区别</h2><p>LinkedHashMap 继承自 HashMap，因此具有和其一样的快速查找的特性。</p>
<p>除此之外，LinkedHashMap 额外维护了一个双向链表，用来维护 Map 元素的插入顺序或者LRU（最近最久未使用）顺序。</p>
<h2 id="数组和链表的区别"><a href="#数组和链表的区别" class="headerlink" title="数组和链表的区别"></a>数组和链表的区别</h2><ul>
<li>数组大小固定，链表则可以动态变化。</li>
<li>数组支持快速随机访问，链表只能通过遍历查找元素。</li>
<li>数组插入和删除元素时，涉及到大量元素的移动操作，性能差；而链表在找到插入位置或删除目标后，只需涉及到指针指向的变化，性能好。</li>
</ul>
<h2 id="手写算法题"><a href="#手写算法题" class="headerlink" title="手写算法题"></a>手写算法题</h2><p>题目一：基本字符串压缩</p>
<blockquote>
<p>利用字符重复出现的次数，编写一个方法，实现基本的字符串压缩功能。比如，字符串“aabcccccaaa”经压缩会变成“a2b1c5a3”。若压缩后的字符串没有变短，则返回原先的字符串。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">zipString</span><span class="params">(String iniString)</span> </span>&#123;</span><br><span class="line">        StringBuilder sb = <span class="keyword">new</span> StringBuilder();</span><br><span class="line"></span><br><span class="line">        <span class="keyword">char</span> ch;</span><br><span class="line">        <span class="keyword">int</span> low = <span class="number">0</span>, high, count;</span><br><span class="line">        <span class="keyword">int</span> len = iniString.length();</span><br><span class="line"></span><br><span class="line">        <span class="keyword">while</span> (low &lt; len) &#123;</span><br><span class="line">            high = low;</span><br><span class="line">            ch = iniString.charAt(low);</span><br><span class="line">            <span class="keyword">while</span> ((high &lt; len) &amp;&amp; (iniString.charAt(high) == ch)) &#123;</span><br><span class="line">                high++;</span><br><span class="line">            &#125;</span><br><span class="line">            count = high - low;</span><br><span class="line">            sb.append(ch);</span><br><span class="line">            sb.append(count);</span><br><span class="line">            low = high;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> (sb.toString().length() &lt; len) ? sb.toString() : iniString;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>题目二：实现简单哈希表以及查找功能</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HashTable</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> List[] base = <span class="keyword">new</span> List[<span class="number">16</span>];</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">HashTable</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; base.length; i++) &#123;</span><br><span class="line">            base[i] = <span class="keyword">new</span> ArrayList&lt;String&gt;();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">hash</span><span class="params">(String elem)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (elem == <span class="keyword">null</span>) <span class="keyword">return</span> -<span class="number">1</span>;</span><br><span class="line">        <span class="keyword">return</span> elem.hashCode() % <span class="number">16</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">add</span><span class="params">(String str)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> hash = hash(str);</span><br><span class="line">        <span class="keyword">if</span> (hash == -<span class="number">1</span>) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(<span class="string">"Can't add null!"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        base[hash].add(str);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">find</span><span class="params">(String str)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (str == <span class="keyword">null</span>) <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        <span class="keyword">int</span> hash = hash(str);</span><br><span class="line">        List&lt;String&gt; temp = base[hash];</span><br><span class="line">        <span class="keyword">for</span> (String s : temp) &#123;</span><br><span class="line">            <span class="keyword">if</span> (s.equals(str)) <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="10亿整数，1G内存，快速去重"><a href="#10亿整数，1G内存，快速去重" class="headerlink" title="10亿整数，1G内存，快速去重"></a>10亿整数，1G内存，快速去重</h2><p>参考博文：<a href="https://blog.csdn.net/hustwht/article/details/52181643" target="_blank" rel="noopener">https://blog.csdn.net/hustwht/article/details/52181643</a></p>
<h2 id="什么是虚拟内存（操作系统）"><a href="#什么是虚拟内存（操作系统）" class="headerlink" title="什么是虚拟内存（操作系统）"></a>什么是虚拟内存（操作系统）</h2><p>让物理内存扩充成更大的逻辑内存，从而让程序获得更多的可用内存。一个程序不需要全部调入内存就可以运行，这使得有限的内存运行大程序成为可能。</p>
<h2 id="虚拟内存的最大容量由什么决定"><a href="#虚拟内存的最大容量由什么决定" class="headerlink" title="虚拟内存的最大容量由什么决定"></a>虚拟内存的最大容量由什么决定</h2><p>由计算机的地址结构决定，即 CPU 的位数。64位系统环境下，虚拟内存技术使得进程可用内存空间达<strong>2的64次幂字节</strong>，显然这只是理论数值。</p>
<h2 id="进程和线程的区别"><a href="#进程和线程的区别" class="headerlink" title="进程和线程的区别"></a>进程和线程的区别</h2><p>进程是执行着的应用程序，而线程是进程内部的一个执行序列。一个进程可以有多个线程。线程又叫做轻量级进程。</p>
<ul>
<li><p><strong>地址空间和其它资源</strong>：进程间相互独立，同一进程的各线程间共享。某进程内的线程在其它进程不可见。</p>
</li>
<li><p><strong>通信</strong>：进程间通信（<a href="https://baike.baidu.com/item/ipc/19486140?fr=aladdin" target="_blank" rel="noopener">IPC技术</a>），线程间可以直接读写进程数据段（如全局变量）来进行通信——需要进程同步和互斥手段的辅助，以保证数据的一致性。</p>
</li>
<li><p><strong>调度和切换</strong>：线程上下文切换比进程上下文切换要快得多。</p>
</li>
<li><p>在多线程操作系统中，进程不是一个可执行的实体。</p>
</li>
</ul>
<h2 id="网络-ARP-协议的作用"><a href="#网络-ARP-协议的作用" class="headerlink" title="网络 ARP 协议的作用"></a>网络 ARP 协议的作用</h2><p>ARP 是地址解析协议，解决 IP 地址到硬件 MAC 地址的映射问题。</p>
<h2 id="说几个熟悉的-HTTP-状态码"><a href="#说几个熟悉的-HTTP-状态码" class="headerlink" title="说几个熟悉的 HTTP 状态码"></a>说几个熟悉的 HTTP 状态码</h2><p>2xx 成功</p>
<ul>
<li>200 OK：一切正常</li>
</ul>
<p>3xx 重定向</p>
<ul>
<li>301 Moved Permanently：客户请求的文档在其他地方</li>
</ul>
<p>4xx 客户机中出现的错误</p>
<ul>
<li>400 Bad Request：请求出现语法错误</li>
<li>401 Unauthorized：客户视图未经授权访问受密码保护的页面</li>
<li>403 Forbiden：资源不可用。请求被拒绝</li>
<li>404 Not Found：无法找到指定位置的资源</li>
</ul>
<p>5xx 服务器中出现的错误</p>
<ul>
<li>500 Inernal Server Error：服务器遇到意料不到的情况，不能完成客户请求</li>
<li>501 Not Implemented：服务器不支持实现请求所需要的功能</li>
<li>502 Bad Gateway：服务器作为网关或代理，为了完成请求访问下一个服务器，该服务器返回了非法的应答</li>
<li>503 Service Unavailable：服务器由于维护或负载过重未能应答</li>
<li>504 Gateway Timeout：服务器作为网关或代理，不能及时从远程服务器获得应答</li>
<li>505 HTTP Version Not Supported：服务器不支持请求中所指明的 HTTP 版本（HTTP 1.1新）</li>
</ul>
<h2 id="Linux-查看进程端口"><a href="#Linux-查看进程端口" class="headerlink" title="Linux 查看进程端口"></a>Linux 查看进程端口</h2><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 先查找进程的 PID</span></span><br><span class="line">ps -ef | grep thread_name</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看进程端口</span></span><br><span class="line">netstat -anp | grep PID</span><br></pre></td></tr></table></figure>
<h2 id="Linux-kill-9-和-kill-15-的区别"><a href="#Linux-kill-9-和-kill-15-的区别" class="headerlink" title="Linux kill -9 和 kill -15 的区别"></a>Linux kill -9 和 kill -15 的区别</h2><p><code>kill</code>的参数其实是信号编号。</p>
<p><strong>SIGKILL(9)</strong>：立即杀死进程。该信号不能被阻塞，处理和忽略。不推荐~</p>
<p><strong>SIGTERM(15)</strong>：正常退出进程，退出前可以被阻塞或回调处理。并且它是 Linux 缺省的程序中断信号。推荐使用！</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 查看全部的信号编号</span></span><br><span class="line">kill -l</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>手滑了就鼓励一下吧~</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt=" 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    justZero
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://alonezero.github.io/posts/a3744c3a/" title="神策数据电话面试">https://alonezero.github.io/posts/a3744c3a/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/面试/" rel="tag"># 面试</a>
          
            <a href="/tags/神策数据/" rel="tag"># 神策数据</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/posts/9e4eea06/" rel="next" title="CVTE 电话面试">
                <i class="fa fa-chevron-left"></i> CVTE 电话面试
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/posts/cbfbce13/" rel="prev" title="Electron 使用 Node 原生模块“踩坑”">
                Electron 使用 Node 原生模块“踩坑” <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.png"
                alt="" />
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">19</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/alonezero" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:alonezero@foxmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/zero-gu-du" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-globe"></i>知乎</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/9339c3f2fd67" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-globe"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#HashMap-底层原理"><span class="nav-number">1.</span> <span class="nav-text">HashMap 底层原理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HashMap-如何解决哈希冲突"><span class="nav-number">2.</span> <span class="nav-text">HashMap 如何解决哈希冲突</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HashMap-和-Hashtable-的区别"><span class="nav-number">3.</span> <span class="nav-text">HashMap 和 Hashtable 的区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Hashtable-如何保证线程安全"><span class="nav-number">4.</span> <span class="nav-text">Hashtable 如何保证线程安全</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HashMap-如何变得线程安全"><span class="nav-number">5.</span> <span class="nav-text">HashMap 如何变得线程安全</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HashMap-和-LinkedHashMap-的区别"><span class="nav-number">6.</span> <span class="nav-text">HashMap 和 LinkedHashMap 的区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数组和链表的区别"><span class="nav-number">7.</span> <span class="nav-text">数组和链表的区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#手写算法题"><span class="nav-number">8.</span> <span class="nav-text">手写算法题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#10亿整数，1G内存，快速去重"><span class="nav-number">9.</span> <span class="nav-text">10亿整数，1G内存，快速去重</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#什么是虚拟内存（操作系统）"><span class="nav-number">10.</span> <span class="nav-text">什么是虚拟内存（操作系统）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#虚拟内存的最大容量由什么决定"><span class="nav-number">11.</span> <span class="nav-text">虚拟内存的最大容量由什么决定</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#进程和线程的区别"><span class="nav-number">12.</span> <span class="nav-text">进程和线程的区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#网络-ARP-协议的作用"><span class="nav-number">13.</span> <span class="nav-text">网络 ARP 协议的作用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#说几个熟悉的-HTTP-状态码"><span class="nav-number">14.</span> <span class="nav-text">说几个熟悉的 HTTP 状态码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Linux-查看进程端口"><span class="nav-number">15.</span> <span class="nav-text">Linux 查看进程端口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Linux-kill-9-和-kill-15-的区别"><span class="nav-number">16.</span> <span class="nav-text">Linux kill -9 和 kill -15 的区别</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder"></span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.3</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.3"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'SlJNvJpMosEFPpudAOQzXaiM-gzGzoHsz',
        appKey: 'QbBAt982UuxShvhyqB7YCbt6',
        placeholder: '(゜-゜)つロ 干杯',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('-1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("SlJNvJpMosEFPpudAOQzXaiM-gzGzoHsz", "QbBAt982UuxShvhyqB7YCbt6");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  
  


  

  

</body>
</html>
